<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="x-ua-compatible" content="ie=edge">
		<title></title>
		<meta name="description" content="Neat">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" user-scalable="no">
		<link rel="stylesheet" href="index.css">
		<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
		<script src="https://www.jq22.com/demo/sweetalert-master-150108224250/lib/sweet-alert.js"></script>
		<link rel="stylesheet" href="https://www.jq22.com/demo/sweetalert-master-150108224250/lib/sweet-alert.css">
	</head>
	<body>

		<div class="main-group">
			<h1 style="font-size: 28px;text-align: center;">报平安登记</h1>
			<div class="form-group">
				<div class="form" id="form" style="flex-direction: column;">

					<select name="" id="classNum" class="text-input" style="flex:none;">
						<option value="00">选择班级</option>
					</select>
					<br>
					<input id="num" class="text-input" type="number" min="1" max="44" placeholder="输入班号" />
					<br>
					<input id="name" class="text-input" placeholder="输入姓名" />
					<br>
					<input id="qq" class="text-input" placeholder="输入QQ" />
					<br>
					<button type="submit" class="btn submit-btn" onclick="set()" style="height: 40px;">添加</button>
				</div>
			</div>
			<div id="note">
				<ul class="items-group">

				</ul>
			</div>
			<span id="nos"></span>
			<div class="icon success animate" style="display: block;"> <span class="line tip animateSuccessTip"></span>
				<span class="line long animateSuccessLong"></span>
				<div class="placeholder"></div>
				<div class="fix"></div>
			</div>
		</div>


	</body>
</html>
<script type="text/javascript">
	$.get(`https://39.107.221.29/studentBpa/classNum.php`,
		function(data, status) {
			data = JSON.parse(data)
			for (let i of data.number.split(",")) {
				$("#classNum")[0].innerHTML += `<option value="${i}">22${i<10?"0"+i:i}</option>`
			}
		})

	function set() {
		let classNum = $("#classNum").val()
		let name = $("#name").val()
		let qq = $("#qq").val()
		let num = $("#num").val()
		$.get(`https://39.107.221.29/studentBpa/addStu.php?qq=${qq}&classNum=${classNum}&name=${name}&num=${num}`,
			function(data,
				status) {
				if (data == "") {

				} else {
					data = JSON.parse(data)
					if (data.code != 200) {
						swal({
							title: "失败",
							type: "error",
							text: "可能是学号重复",
							confirmButtonText: "好的"
						});
					}else{
						swal({
							title: "成功",
							type: "success",
							text: "添加成功",
							confirmButtonText: "好的"
						});
					}
				}
			})
		// alert("数据: " + data + "\n状态: " + status);
	}
</script>
